package com.model;

/**
 * @author Erik
 * 2017-08-13
 * 公司部门类
 * @apiNote public void addEmployee(Employees employees) 添加员工
 */
public class Company {
    private String departName;
    private int memberNumber;
    private Employees[] employees;

    public Company(){}

    public Company(String departName,int memberNumber,Employees[] employees){
        this.setDepartName(departName);
        this.setMemberNumber(memberNumber);
        this.setEmployees(employees);
    }

    public Company(String departName){
        this.setDepartName(departName);
    }
    //Setters
    public void setDepartName(String departName)        {   this.departName=departName;     }
    public void setMemberNumber(int memberNumber)       {   this.memberNumber=memberNumber; }
    public void setEmployees(Employees[] employees)     {   this.employees = employees;   }

    //Getters
    public String getDepartName()           {   return this.departName;     }

    public int getMemberNumber()            {   return this.memberNumber;   }
    public Employees[] getEmployees()
    {
        if(this.employees ==null)
            this.employees =new Employees[200];
        return this.employees;
    }


    /**
     * 添加成员
     * 实现双向联系
     * @param employees 成员类对象
     */
    public void addEmployee(Employees employees){
        for(int i = 0; i<this.getEmployees().length; i++){
            if(this.getEmployees()[i]==null){
                employees.setDepartment(this);
                this.getEmployees()[i]= employees;
                this.memberNumber=i+1;
                return;
            }
        }
    }

    public String info(){
        String information=this.getDepartName()+"共有"+this.getMemberNumber()+"名员工";
        return information;
    }
}
